/*
 * @Author: didididijiajiajia 11643763+didididijiajiajia@user.noreply.gitee.com
 * @Date: 2024-04-03 17:45:22
 * @LastEditors: didididijiajiajia 11643763+didididijiajiajia@user.noreply.gitee.com
 * @LastEditTime: 2024-04-03 17:51:43
 * @FilePath: \react全栈\vue_ts-server\schema\article.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
let joi = require('joi');
// 允许未设置规则的未知键
joi = joi.defaults((schema) =>
  schema.options({
    allowUnknown: true
  })
);
const articleSchema = Joi.object({
  title: Joi.string().required().min(3).max(255)
    .messages({
      'string.base': `"title" should be a type of 'text'`,
      'string.empty': `"title" cannot be an empty field`,
      'string.min': `"title" should have a minimum length of {#limit}`,
      'string.max': `"title" should have a maximum length of {#limit}`,
      'any.required': `"title" is a required field`
    }),
  content: Joi.string().required().min(10)
    .messages({
      'string.base': `"content" should be a type of 'text'`,
      'string.empty': `"content" cannot be an empty field`,
      'string.min': `"content" should have a minimum length of {#limit}`,
      'any.required': `"content" is a required field`
    }),
  create_time: Joi.date().optional(),
  likes: Joi.number().integer().min(0).optional()
    .messages({
      'number.base': `"likes" should be a number`,
      'number.integer': `"likes" should be an integer`,
      'number.min': `"likes" should not be less than {#limit}`
    }),
  dislikes: Joi.number().integer().min(0).optional()
    .messages({
      'number.base': `"dislikes" should be a number`,
      'number.integer': `"dislikes" should be an integer`,
      'number.min': `"dislikes" should not be less than {#limit}`
    })
});

export const create_article= Joi.object({
    title: Joi.string().required().min(3).max(255),
    content: Joi.string().required().min(10),
    likes: Joi.number().integer().min(0).default(0),
    dislikes: Joi.number().integer().min(0).default(0)
  });
 export  const delete_article = Joi.object({
    id: Joi.number().integer().required()
  });
 export  const update_article = Joi.object({
    title: Joi.string().min(3).max(255).optional(),
    content: Joi.string().min(10).optional(),
    likes: Joi.number().integer().min(0).optional(),
    dislikes: Joi.number().integer().min(0).optional(),
  }).min(1);
module.exports = articleSchema;